package com.jingjiu.homeservicesbiz.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jingjiu.homeservicesapi.domain.HouseService;
import com.jingjiu.homeservicesapi.util.R;
import com.jingjiu.homeservicesbiz.service.HouseServiceServiceImpl;


import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


/**
 * 家政服务：记录各种家政服务的基本信息Controller
 * 
 * @author ruoyi
 * @date 2025-04-16
 */
@RestController
@RequestMapping("/system/service")
public class HouseServiceController
{

    @Autowired
    private HouseServiceServiceImpl houseServiceService;


    @GetMapping("/page")
    public R<Page<HouseService>> getPage(@ParameterObject Page<HouseService> page,
                                         @ParameterObject HouseService houseService) {
        Page<HouseService> houseServicePage = houseServiceService.selectPage(page, houseService);
        if(houseServicePage==null)
            return R.failed();
        // 调用 Service 层进行分页查询
        return R.ok(houseServicePage);
    }


/*
    *//**
     * 导出家政服务：记录各种家政服务的基本信息列表
     *//*

    @PostMapping("/export")
    @ResponseBody
    public R<List<HouseService>> export(HouseService houseService)
    {
       return R.ok(houseServiceService.selectHouseServiceList(houseService));

    }*/



    /**
     * 新增保存家政服务：记录各种家政服务的基本信息
     */

    @PostMapping("/update")
    @ResponseBody
    public  R addSave(@RequestBody HouseService houseService)
    {
        int row = houseServiceService.insertHouseService(houseService);
        if(row!=1)
            return R.failed();
        return R.ok(row);
    }

    /**
     * 修改家政服务：记录各种家政服务的基本信息
     */

    @GetMapping("/get/{id}")
    public R<HouseService> getById(@PathVariable("id") Long id)
    {
        HouseService houseService = houseServiceService.selectHouseServiceById(id);
        if(houseService==null)
            return R.failed();
        return R.ok(houseService);


    }

    /**
     * 修改保存家政服务：记录各种家政服务的基本信息
     */

    @PostMapping("/edit")
    @ResponseBody
    public R editSave(@RequestBody HouseService houseService)
    {
        int row = houseServiceService.updateHouseService(houseService);
        if(row!=1)
            return R.failed();
        return R.ok(row);
    }

    /**
     * 删除家政服务：记录各种家政服务的基本信息
     */

    @PostMapping( "/remove")
    @ResponseBody
    public R remove(Long id)
    {
        int row = houseServiceService.deleteHouseServiceById(id);
        if(row!=1)
            return R.failed();
        return R.ok(row);
    }
}
